package com.app.mp3player.adapter;

import java.util.List;

import com.app.mp3player.R;
import com.app.mp3player.model.Mp3Info;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class Mp3ListAdapter extends BaseAdapter {
	private List<Mp3Info> mp3Infos;
	private LayoutInflater inflater;
	
	public Mp3ListAdapter(Context context,List<Mp3Info> data) {
		inflater = LayoutInflater.from(context);
		mp3Infos = data;
	}

	@Override
	public int getCount() {
		return mp3Infos.size();
	}

	@Override
	public Object getItem(int position) {
		return mp3Infos.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View view, ViewGroup group) {
		if(view == null){
			view = inflater.inflate(R.layout.list_item, null);
		}
		Mp3Info mp3Info = mp3Infos.get(position);
		TextView nameView = (TextView)view.findViewById(R.id.mp3_name);
		nameView.setText(mp3Info.getMp3Name());
		TextView authorView = (TextView)view.findViewById(R.id.mp3_author);
		authorView.setText(mp3Info.getAuthor());
		return view;
	}

}
